// https://soj.turingedu.cn/problem/50301/
// https://www.luogu.com.cn/problem/P2513
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
int rad(); // read int
const int max_size = 5 + 1e3;
const int maxn = 5 + 1e3;
const int mod = 1e4;

int n, maxj;
int f[maxn][max_size]; // f[i][j]: 1~n 的全排列中，逆序对数量为 j 的方案数
int pre[maxn];         // pre[j] = sum(f[now][1~j])
/*
考虑插入 i 到 i - 1 的全排列，
    f[i][j] = sum(f[i - 1][j - k]), k->[0, min(i - 1, j)]
        当 k->[0 ~ min(j, i - 1)] 时，(j - k)->[j ~ max(0, j - i + 1)]
    f[i][j] sum(f[i - 1][k]), k->[max(0, j - i + 1), j]
*/
int main() {
    n = rad(), maxj = rad();
    pre[0] = 1;
    for (int i = 1; i <= n; ++i) {
        rf(j, maxj) pre[j] = pre[j - 1] + f[i - 1][j];
        for (int j = 1; j <= maxj; ++j) {
            int st = max(0, j - i + 1);
            if (st - 1 >= 0)
                f[i][j] = (pre[j] - pre[st - 1]) % mod;
            else
                f[i][j] = pre[j] % mod;
        }
    }
    printf("%d\n", f[n][maxj]);
}

int rad() {
    int back = 0, ch = 0, neg = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        neg = ch == '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return (back ^ -neg) + neg;
}